package kr.hkit.powerjava.chapter12.work;

import java.util.Arrays;
import java.util.Comparator;

public class PersonTest{
	public static void main(String[] args) {
		Person[] arr = new Person[3];
		arr[0] = new Person("최석열", 177);
		arr[1] = new Person("김태희", 160);
		arr[2] = new Person("김주하", 170);
		
		System.out.println("키가 가장 큰 사람은 "+getMaximum(arr));

		
		int a = Arrays.binarySearch(arr, new Person("김태희"));
		System.out.println(a);
		
		Comparator<Person> nameSort = new Comparator<Person>() {

			@Override
			public int compare(Person o1, Person o2) {
				
				return o2.getName().hashCode() - o1.getName().hashCode();
			}
			
		};
		
		Arrays.sort(arr, nameSort);
		prnArr(arr);
	
	}	
	
	private static void prnArr(Person[] arr) {
		for(Person p : arr) {
			System.out.println(p);
		}
		
	}

	public static String getMaximum(Person[] array) {
		Arrays.sort(array);
		prnArr(array);
		return array[array.length -1].getName();
	}
}
